﻿//Start SuryaniUI Base
var SuryaniUI = {};
SuryaniUI.extend = function (destination, source) {
    for (var property in source) {
        if (destination[property]) {
            continue;
        }
        destination[property] = source[property];
    }
    return destination;
};
SuryaniUI.clone = function (matrix) {
    if (typeof (matrix) == "function") {
        return new matrix();
    }
    else if (typeof (matrix) == "object") {
        var cloning = new Object();
        for (var member in matrix) {
            switch (typeof (matrix[member])) {
                case "object":
                    cloning[member] = clone(matrix[member]);
                    break;
                default:
                    cloning[member] = matrix[member];
            }
        }
        return cloning;
    }
    else {
        var cloning = matrix;
        return cloning;
    }
}
SuryaniUI.getWindowWidth = function (objWindow) {
    if (objWindow.innerWidth) {
        return Math.min(objWindow.innerWidth, objWindow.document.documentElement.clientWidth);
    }
    else {
        return objWindow.document.documentElement.clientWidth;
    }
}
SuryaniUI.getWindowHeight = function (objWindow) {
    if (objWindow.innerHeight) {
        return Math.min(objWindow.innerHeight, objWindow.document.documentElement.clientHeight);
    }
    else {
        return objWindow.document.documentElement.clientHeight;
    }
}
SuryaniUI.getDocumentScrollTop = function (objDocument) {
    return Math.max(objDocument.documentElement.scrollTop, objDocument.body.scrollTop);
}
SuryaniUI.getDocumentScrollLeft = function (objDocument) {
    return Math.max(objDocument.documentElement.scrollLeft, objDocument.body.scrollLeft);
}
SuryaniUI.getDocumentWidth = function (objDocument) {
    return objDocument.documentElement.scrollWidth;
}
SuryaniUI.getDocumentHeight = function (objDocument) {
    return objDocument.documentElement.scrollHeight;
}
SuryaniUI.maxZIndex = function (objDocument) {
    var zIndex = 0;
    var elments = objDocument.getElementsByTagName("*");
    for (var i = 0; i < elments.length; i++) {
        if (elments[i].currentStyle) {
            elementZIndex = elments[i].currentStyle.zIndex; //get z-index on IE
        } else if (window.getComputedStyle) {
            elementZIndex = window.getComputedStyle(elments[i], null).zIndex; //get z-index on Firfox, Safari and Chrome
        }
        if (elementZIndex) {
            if (zIndex < parseInt(elementZIndex)) {
                zIndex = elementZIndex;
            }
        }
    }
    return parseInt(zIndex);
}
SuryaniUI.BindEvent = function (element, type, listener) {
    if (window.addEventListener) {
        element.addEventListener(type, listener, false);
    }
    else if (window.attachEvent) {
        element.attachEvent('on' + type, listener);
    }
}
SuryaniUI.userAgent = navigator.userAgent.toLowerCase();
SuryaniUI.browser = {
    version: (SuryaniUI.userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(SuryaniUI.userAgent),
    opera: /opera/.test(SuryaniUI.userAgent),
    msie: /msie/.test(SuryaniUI.userAgent) && !/opera/.test(SuryaniUI.userAgent),
    mozilla: /mozilla/.test(SuryaniUI.userAgent) && !/(compatible|webkit)/.test(SuryaniUI.userAgent)
};
SuryaniUI.phoneList = new Array("2.0 MMP", "240320", "AvantGo", "BlackBerry", "Blazer", "Cellphone", "Danger", "DoCoMo", "Elaine/3.0", "EudoraWeb",
    "hiptop", "IEMobile", "KYOCERA/WX310K", "LG/U990", "MIDP-2.0", "MMEF20", "MOT-V", "NetFront", "Newt", "Nintendo Wii",
    "Nitro", "Nokia", "Opera Mini", "Opera Mobi", "Palm", "Playstation Portable", "portalmmm", "Proxinet", "ProxiNet",
    "SHARP-TQ-GX10", "Small", "SonyEricsson", "Symbian", "TS21i-10", "UP.Browser", "UP.Link", "Windows CE", "WinWAP",
    "iPhone", "iPod", "Windows Phone", "HTC", "ucweb", "Mobile", "Android");
SuryaniUI.isOnTouchStart = function () {
    return typeof (ontouchstart) != "undefined";
}
SuryaniUI.isiPad = function () {
    return SuryaniUI.userAgent.indexOf("ipad") >= 0;
}
SuryaniUI.isAndroid = function () {
    return SuryaniUI.userAgent.indexOf("Android") > -1;
}
SuryaniUI.isiPhone = function () {
    return (navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1);
}
SuryaniUI.isPhone = function () {
    if (SuryaniUI.isOnTouchStart() && !SuryaniUI.isiPad()) {
        return true;
    }
    for (var i = 0; i < SuryaniUI.phoneList.length; i++) {
        if (SuryaniUI.userAgent.indexOf(SuryaniUI.phoneList[i].toLowerCase()) >= 0 && SuryaniUI.userAgent.indexOf("ipad") == -1) {
            return true;
        }
    }
    var appNameList = new Array("Microsoft Pocket Internet Explorer");
    for (var i = 0; i < appNameList.length; i++) {
        if (SuryaniUI.userAgent.indexOf(appNameList[i]) >= 0) {
            return true;
        }
    }
    return false;
}
SuryaniUI.isMobile = function () {
    return SuryaniUI.isOnTouchStart() || SuryaniUI.isPhone() || SuryaniUI.isiPad();
}

//End SuryaniUI

/**
 * Suryani UI for Jump to an anchor target
 * Description：
 *     If the page url includes a hash, then get the object of anchor tag.
 * Example:
 *     SuryaniUI.isDirectToHash() - [true] this page has a hash should be jumped to. [false] no hash.
 *     SuryaniUI.posHref - the object of anchor tag. For instance, $(SuryaniUI.posHref).offset().top - the top of the anchor element。
 * Log:
 *     QS-43926 CO19383 - Create
 */
SuryaniUI.posHref = null;
SuryaniUI.isDirectToHash = function () {
    var hash = window.location.hash;
    if (typeof (hash) != "undefined" && hash.match(/#.+/g)) {
        var posHref = hash.match(/#.+/g);
        posHref = posHref[0].replace(/([ ;&,.+*~\':"!^$[\]()=>|\/@])/g, function (word) {
            return "\\" + word;
        });
        if ($(posHref).length > 0) {
            SuryaniUI.posHref = posHref;
            return true;
        }
    }
    return false;
}
//End Suryani UI for Jump to an anchor target

//Start SuryaniUIList
function SuryaniUIList() {
    this.data = new Array();
}
SuryaniUIList.prototype.count = function () {
    return this.data.length;
}
SuryaniUIList.prototype.indexOf = function (item) {
    var index = -1;
    for (var i = this.count(); i >= 0;) {
        if (this.data[--i] == item) {
            index = i;
            break;
        }
    }
    return index;
}
SuryaniUIList.prototype.contain = function (item) {
    return this.indexOf(item) == -1 ? false : true;
}
SuryaniUIList.prototype.add = function (item) {
    if (this.contain(item)) {
        return;
    }
    this.data.push(item);
}
SuryaniUIList.prototype.removeAt = function (index) {
    for (var i = index; i < this.count() - 1; i++) {
        this[i] = this[i + 1];
    }
    return this.data.pop();
}
SuryaniUIList.prototype.item = function (index) {
    if (index >= 0 && index <= this.count() - 1) {
        return this.data[index]
    }
}
SuryaniUIList.prototype.remove = function (item) {
    var index = this.indexOf(item);
    if (index != -1) {
        return this.removeAt(index);
    }
    return null;
}
//End SuryaniUIList

/*******************************
 Suryani Common Hopup Prototypes
 ********************************/
var suryaniPopupZIndex = 10000;
function suryaniPopupMaxZindex(action) {
    if (action == "remove")
        suryaniPopupZIndex -= 1;
    else {
        suryaniPopupZIndex += 1;
        return suryaniPopupZIndex;
    }
}
//Start SuryaniMaskPopup
function SuryaniMaskPopup(param) {
    this.targetWindow = param["targetWindow"] || window;
    this.elementKey = new Array();
    this.element = new Object();
    this.style = new Object();
    this.cssClass = new Object();

    this.elementKey.push("maskSpan");
    this.elementKey.push("maskDiv");
    this.element["maskSpan"] = this.targetWindow.document.createElement("span");
    this.element["maskDiv"] = this.targetWindow.document.createElement("div");
    this.element["maskDiv"].setAttribute("class", "maskBackground");
    this.element["maskDiv"].setAttribute("className", "maskBackground");
    this.style["maskDiv"] = { zIndex: suryaniPopupMaxZindex(), display: "block" };
//	$(this.element["maskDiv"]).live("click", function () {
//		suryaniHtmlWrapHopupObj.hide();
//  });
}
SuryaniMaskPopup.prototype.setStyle = function () {
    this.element.maskDiv.style.zIndex = this.style["maskDiv"]["zIndex"];
    this.element.maskDiv.style.display = this.style["maskDiv"]["display"];
}

SuryaniMaskPopup.prototype.setSize = function () {
    this.element.maskDiv.style.width = "100%";
    this.element.maskDiv.style.height = Math.max(SuryaniUI.getWindowHeight(this.targetWindow), SuryaniUI.getDocumentHeight(this.targetWindow.document)) + "px";
}

SuryaniMaskPopup.prototype.setPosition = function () {
    this.element.maskDiv.style.left = "0px";
    this.element.maskDiv.style.top = "0px";
}
SuryaniMaskPopup.prototype.build = function () {
    //IE6SelectHack
    if (SuryaniUI.browser.msie && parseInt(SuryaniUI.browser.version) <= 6) {
        var html = "<iframe src=\"\" style=\"z-index:-1;background-color:transparent;width:100%;height:100%\"></iframe>";
        this.element.maskDiv.insertAdjacentHTML("beforeEnd", html);
    }
    this.element.maskSpan.appendChild(this.element.maskDiv);
    this.targetWindow.document.body.appendChild(this.element.maskSpan);
}
SuryaniMaskPopup.prototype.bindEvent = function () {
    var me = this;
    SuryaniUI.BindEvent(this.targetWindow, "resize", function () {
        me.setSize();
    });
}
SuryaniMaskPopup.prototype.show = function () {
    this.setSize();
    this.setStyle();
    this.build();
    this.setPosition();
    this.bindEvent();
}
SuryaniMaskPopup.prototype.close = function () {
    this.targetWindow.document.body.removeChild(this.element.maskSpan);
    suryaniPopupMaxZindex("remove");
}
//End MaskPopup
function SuryaniPopup(param) {
    this.targetWindow = param["targetWindow"] || window;

    this.elementKey = new Array();
    this.config = new Object();
    this.element = new Object();
    this.callBack = new Object();
    this.cssClass = new Object();
    this.style = new Object();
    this.size = new Object();
    this.position = new Object();
    this.action = new Object();
    this.actionData = new Object();
    this.config["targetObj"] = param.targetObj || "";

    if (param.showMask) {
        this.config["showMask"] = param.showMask;
        this.mask = new SuryaniMaskPopup({ targetWindow: this.targetWindow});
    }

    this.config["title"] = param.title;
    this.config["className"] = param.className || "";
    this.config["content"] = param.content;
    this.config["autoSize"] = false;
    this.config["hasArrow"] = param.hasArrow || false;
    this.callBack["closeCallBack"] = param.closeCallBack;

    this.size["width"] = param.width || 300;
    this.size["height"] = param.height || 180;

    this.position["top"] = param.top;
    this.position["left"] = param.left;

    this.init();
}

SuryaniPopup.prototype.init = function () {
    this.action["hasShow"] = false;

    this.elementKey.push("popupSpan");
    this.elementKey.push("popupDiv");
    this.elementKey.push("popupBorderTop");
    this.elementKey.push("popupBorderBottom");
    this.elementKey.push("popupContent");

    this.elementKey.push("SuryaniCloseDiv");
    this.elementKey.push("SuryaniReturnBtn");
    this.elementKey.push("headerDiv");

    this.elementKey.push("contentDiv");
    this.element["popupSpan"] = this.targetWindow.document.createElement("span");
    this.element["popupSpan"].setAttribute("class", "suryaniPopupWrap" + this.config["className"]);
    this.element["popupSpan"].setAttribute("className", "suryaniPopupWrap" + this.config["className"]);
    this.element["popupDiv"] = this.targetWindow.document.createElement("div");
    this.element["popupDiv"].setAttribute("class", "suryaniPopup" + this.config["className"]);
    this.element["popupDiv"].setAttribute("className", "suryaniPopup" + this.config["className"]);

    this.element["popupBorderTop"] = this.targetWindow.document.createElement("div");
    this.element["popupBorderTop"].setAttribute("class", "suryaniPopupTop clearfix");
    this.element["popupBorderTop"].setAttribute("className", "suryaniPopupTop clearfix");
    this.element["popupBorderTop"].innerHTML = "<div class=\"suryaniPopupTopLeft\"> </div><div class=\"suryaniPopupTopRight\"> </div>";

    this.element["popupBorderBottom"] = this.targetWindow.document.createElement("div");
    this.element["popupBorderBottom"].setAttribute("class", "suryaniPopupBtm clearfix");
    this.element["popupBorderBottom"].setAttribute("className", "suryaniPopupBtm clearfix");
    this.element["popupBorderBottom"].innerHTML = "<div class=\"suryaniPopupBtmLeft\"> </div><div class=\"suryaniPopupBtmRight\"> </div>";

    this.element["popupContent"] = this.targetWindow.document.createElement("div");
    this.element["popupContent"].setAttribute("class", "suryaniPopupContent");
    this.element["popupContent"].setAttribute("className", "suryaniPopupContent");

    this.element["headerDiv"] = this.targetWindow.document.createElement("div");
    this.element["headerDiv"].setAttribute("class", "suryaniPopupTitle");
    this.element["headerDiv"].setAttribute("className", "suryaniPopupTitle");

    this.element["SuryaniCloseDiv"] = this.targetWindow.document.createElement("div");
    this.element["SuryaniCloseDiv"].setAttribute("class", "suryaniCloseBtn");
    this.element["SuryaniCloseDiv"].setAttribute("className", "suryaniCloseBtn");
    this.element["SuryaniReturnBtn"] = this.targetWindow.document.createElement("div");
    this.element["SuryaniReturnBtn"].setAttribute("class", "suryaniReturnBtn");
    this.element["SuryaniReturnBtn"].setAttribute("className", "suryaniReturnBtn");

    this.element["contentDiv"] = this.targetWindow.document.createElement("div");
    this.element["contentDiv"].setAttribute("class", "suryaniIframeContent");
    this.element["contentDiv"].setAttribute("className", "suryaniIframeContent");

    this.style["popupDiv"] = {position: "absolute"};

    this.style["popupDiv"]["zIndex"] = suryaniPopupMaxZindex();

    if (this.config["hasArrow"]) {
        this.elementKey.push("popupArrow");
        this.element["popupArrow"] = this.targetWindow.document.createElement("div");
        this.element["popupArrow"].setAttribute("class", "suryaniArrow");
        this.element["popupArrow"].setAttribute("className", "suryaniArrow");
    }
}

//initContent
SuryaniPopup.prototype.initContent = function () {
}
//setStyle
SuryaniPopup.prototype.setStyle = function () {
    for (var i = this.elementKey.length - 1; i > 0; i--) {
        var key = this.elementKey[i];
        if (!this.style[key]) {
            continue;
        }
        for (var styleItem in this.style[key]) {
            try {
                this.element[key].style[styleItem] = this.style[key][styleItem];
            }
            catch (e) {
            }
        }
    }
}
SuryaniPopup.prototype.setClass = function () {
    for (var i = this.elementKey.length - 1; i > 0; i--) {
        var key = this.elementKey[i];
        if (!this.cssClass[key]) {
            continue;
        }
        try {
            this.element[key].className = this.cssClass[key];
        }
        catch (e) {
        }
    }
}
//setSize
SuryaniPopup.prototype.setSize = function () {
    this.element.popupDiv.style["width"] = (parseInt(this.size.width)) + "px";
    //this.element.popupDiv.style["height"]=this.size.height+"px";
}
//setSize with URL iframe
SuryaniPopup.prototype.setUrlSize = function () {
    //this.element.popupDiv.style["height"]=this.size.height+"px";
}
//reset the size of popup
SuryaniPopup.prototype.resetPopupSize = function (width, height) {
    if (width != "") {
        this.size.width = width;
        this.element["url"].setAttribute("width", width + "px");
    }
    if (height != "") {
        this.size.height = height;
        this.element["url"].setAttribute("height", height + "px");
    }
    this.setSize();
    this.setPosition();
}
//setPosition
SuryaniPopup.prototype.setPosition = function () {
    if (this.position.top) {
        this.element.popupDiv.style["top"] = this.position.top + "px";
    }
    else {
        var availHeight = SuryaniUI.getWindowHeight(this.targetWindow);
        var scrollTop = SuryaniUI.getDocumentScrollTop(this.targetWindow.document);
        if (this.config["targetObj"] != "") {
            availHeight = $(this.config["targetObj"]).height();
            scrollTop = $(this.config["targetObj"]).scrollTop();
        }
        var availTop = 0;
        if (availHeight - this.size.height > 0) {
            availTop = (availHeight - this.size.height) / 2 + scrollTop;
            this.element.popupDiv.style["top"] = availTop + "px";
            if (this.config["showMask"]) {
                this.mask.setSize();
            }
        }
        else {
            availTop = 20 + scrollTop;
            this.element.popupDiv.style["top"] = availTop + "px";
        }
    }
    if (this.position.left) {
        this.element.popupDiv.style["left"] = this.position.left + "px";
    }
    else {
        var availWidth = SuryaniUI.getWindowWidth(this.targetWindow);
        var scrollLeft = SuryaniUI.getDocumentScrollLeft(this.targetWindow.document);
        if (this.config["targetObj"] != "") {
            availHeight = $(this.config["targetObj"]).height();
            scrollTop = $(this.config["targetObj"]).scrollTop();
        }
        var availLeft = 0;
        if (availWidth - this.size.width > 0) {
            availLeft = (availWidth - this.size.width) / 2 + scrollLeft;
        }
        this.element.popupDiv.style["left"] = availLeft + "px";
    }
}
//adjustPosition
SuryaniPopup.prototype.adjustPosition = function () {
}
//build
SuryaniPopup.prototype.build = function () {
    //IE6SelectHack
    if (SuryaniUI.browser.msie && parseInt(SuryaniUI.browser.version) <= 6) {
        var html = "<iframe src=\"\" style=\";position:'absolute';top:0;left:0;z-index:-1;filter:mask();width:100%;height:100%\"></iframe>";
        this.element["popupDiv"].insertAdjacentHTML("beforeEnd", html);
    }

    this.element["popupDiv"].appendChild(this.element["popupBorderTop"]);
    if (this.config["title"] != "") {
        this.element["headerDiv"].innerHTML = this.config["title"];
        this.element["popupContent"].appendChild(this.element["headerDiv"]);
    }
    this.element["popupContent"].appendChild(this.element["contentDiv"]);
    this.element["popupContent"].appendChild(this.element["SuryaniReturnBtn"]);
    this.element["popupContent"].appendChild(this.element["SuryaniCloseDiv"]);
    this.element["popupDiv"].appendChild(this.element["popupContent"]);

    this.element["popupSpan"].appendChild(this.element["popupDiv"]);
    try {
        if (this.config["targetObj"] != "")
            $(this.config["targetObj"]).append(this.element["popupSpan"]);
        else
            this.targetWindow.document.body.appendChild(this.element["popupSpan"]);
    }
    catch (ex) {
        //alert(this.targetWindow.document.body.innerHTML);
        //alert(ex.message);
    }
    this.element["popupDiv"].appendChild(this.element["popupBorderBottom"]);

    if (this.config["hasArrow"]) {
        this.element["popupSpan"].setAttribute("class", "suryaniArrowHopup");
        this.element["popupSpan"].setAttribute("className", "suryaniArrowHopup");
        this.element["popupBorderTop"].appendChild(this.element["popupArrow"]);
    }
}
//buildLoading
SuryaniPopup.prototype.buildLoading = function () {
}
//buildContent
SuryaniPopup.prototype.buildContent = function () {
}
//bindEvents
SuryaniPopup.prototype.bindEvents = function () {
    var me = this;
    $(me.element["SuryaniReturnBtn"]).live("click", function () {
        me.element["SuryaniReturnBtn"].style.display = "none";
        me.element["SuryaniCloseDiv"].style.display = "";
        me.element["url"].setAttribute("src", me.config["SuryaniReturnUrl"]);
        me.config["SuryaniReturnUrl"] = "";
    })//chrome && safari click bug
    SuryaniUI.BindEvent(this.element["SuryaniCloseDiv"], "click", function () {
        me.close();
        if (me.callBack.closeCallBack) {
            me.callBack.closeCallBack();
        }
    });
}
//bindContentEvents
SuryaniPopup.prototype.bindContentEvents = function () {
}
//show
SuryaniPopup.prototype.show = function () {
    this.setStyle();
    this.setClass();
    this.setSize();
    this.setPosition();
    this.bindEvents();
    this.bindContentEvents();
    this.build();
    this.buildLoading();
    this.buildContent();
    if (this.config.showMask) {
        this.mask.show();
    }
    this.action["hasShow"] = true;
}
SuryaniPopup.prototype.showModalDialog = function () {
    this.show();
    this.mask.show();
}
//close
SuryaniPopup.prototype.close = function () {
    if (SuryaniUI.browser.msie && this.config["onFocus"] == true) {
        $(this.element.url).remove();
    }
    if (this.config["targetObj"] != "")
        $(this.config["targetObj"]).find(this.element.popupSpan).remove();
    else
        this.targetWindow.document.body.removeChild(this.element.popupSpan);
    suryaniPopupMaxZindex("remove");
    if (this.config["showMask"]) {
        this.mask.close();
    }
    this.action["hasShow"] = false;
}
//hide
SuryaniPopup.prototype.hide = function () {
    var me = this;
    me.config["content"].parents(".suryaniPopup").css("display", "none");
    me.config["content"].css("display", "none");
    me.config["content"].replaceAll(".suryaniPopupWrap");
    //for SuryaniHtmlWrapHopup
    suryaniPopupMaxZindex("remove");
    if (this.config["showMask"]) {
        this.mask.close();
    }
    this.action["hasShow"] = false;
}
//SuryaniPopup Return Url
SuryaniPopup.prototype.redirect = function (returnUrl, newUrl) {
    var me = this;
    me.config["SuryaniReturnUrl"] = returnUrl;
    me.element["SuryaniReturnBtn"].style.display = "block";
    me.element["SuryaniCloseDiv"].style.display = "none";
    me.element["url"].setAttribute("src", newUrl);
}
//addCallBack
SuryaniPopup.prototype.addCallBack = function (elementKey, listener) {
    elementKey = elementKey.toLowerCase();
    if (this.element[elementKey]) {
        this.callBack[elementKey].add(listener);
    }
}
//removeCallBack
SuryaniPopup.prototype.removeCallBack = function (elementKey, listener) {
    elementKey = elementKey.toLowerCase();
    if (this.element[elementKey]) {
        this.callBack[elementKey].remove(listener);
    }
}

//Start SuryaniUrlHopup
function SuryaniUrlHopup(param) {
    this.base = new SuryaniPopup(param);
    SuryaniUI.extend(this, this.base);
    this.config["autoSize"] = true;
    this.config["onFocus"] = true;
    this.initContent();
}
SuryaniUrlHopup.prototype.initContent = function () {
    this.elementKey.push("loading");
    this.element["loading"] = this.targetWindow.document.createElement("div");
    this.element["loading"].setAttribute("class", "loadingDiv");
    this.element["loading"].setAttribute("className", "loadingDiv");
    this.elementKey.push("url");
    this.element["url"] = this.targetWindow.document.createElement("iframe");
    this.element["url"].setAttribute("border", "0");
    this.element["url"].setAttribute("frameBorder", "0");
    this.element["url"].setAttribute("scrolling", "no");
    this.element["url"].setAttribute("src", this.config["content"]);
    this.element["url"].setAttribute("width", (this.size.width) + "px");
}
SuryaniUrlHopup.prototype.bindContentEvents = function () {
    var me = this;
    SuryaniUI.BindEvent(me.element["url"], "load", function () {
        me.element["loading"].style.display = "none";
    });
    if (this.config["autoSize"]) {
        SuryaniUI.BindEvent(me.element["url"], "load", function () {
            try {
                var obj = me.element["url"];
                if (obj.contentDocument && obj.contentDocument.body.offsetHeight) {
                    obj.height = obj.contentDocument.body.scrollHeight;
                    obj.width = obj.contentDocument.body.scrollWidth;
                }
                else {
                    obj.height = obj.Document.body.scrollHeight;
                    obj.width = obj.Document.body.scrollWidth;
                }
                me.setUrlSize();
                me.size.height = obj.height;
                me.size.width = obj.width;
                me.setPosition();
                me.adjustPosition();

                var contentWindow = obj.contentWindow;
                contentWindow.closeParent = function () {
                    me.close();
                };
                contentWindow.customerFunction = function () {
                    for (var i = 0; i < me.callBack["url"].count(); i++) {
                        me.callBack["url"].item(i)();
                    }
                };
            } catch (e) {
            }
        });
    }
}
SuryaniUrlHopup.prototype.buildLoading = function () {
    this.element["loading"].innerHTML = "<span>Please Wait ...</span>";
    this.element["contentDiv"].appendChild(this.element["loading"]);
    this.element["contentDiv"].appendChild(this.element["url"]);
}
//End SuryaniUrlHopup
//Start SuryaniHasCornerUrlHopup For Wishlist AllSites Hopup
function SuryaniHasCornerUrlHopup(param) {
    this.base = new SuryaniUrlHopup(param);
    SuryaniUI.extend(this, this.base);
    this.initContent();
}
SuryaniHasCornerUrlHopup.prototype.initContent = function () {
    this.elementKey.push("popupCornerLeft");
    this.element["popupCornerLeft"] = this.targetWindow.document.createElement("div");
    this.element["popupCornerLeft"].setAttribute("class", "suryaniCornerLeft");
    this.element["popupCornerLeft"].setAttribute("className", "suryaniCornerLeft");
    this.elementKey.push("popupCornerRight");
    this.element["popupCornerRight"] = this.targetWindow.document.createElement("div");
    this.element["popupCornerRight"].setAttribute("class", "suryaniCornerRight");
    this.element["popupCornerRight"].setAttribute("className", "suryaniCornerRight");
}
SuryaniHasCornerUrlHopup.prototype.buildContent = function () {
    this.element["popupSpan"].setAttribute("class", "suryaniCornerHopup");
    this.element["popupSpan"].setAttribute("className", "suryaniCornerHopup");
    this.element["popupBorderTop"].appendChild(this.element["popupCornerLeft"]);
    this.element["popupBorderTop"].appendChild(this.element["popupCornerRight"]);
}
SuryaniHasCornerUrlHopup.prototype.setSize = function () {
    this.element.popupDiv.style["width"] = (parseInt(this.size.width) + 50) + "px";
}
//End SuryaniHasCornerUrlHopup
//Start SuryaniHtmlHopup
function SuryaniHtmlHopup(param) {
    this.base = new SuryaniPopup(param);
    SuryaniUI.extend(this, this.base);
    this.initContent();
}
SuryaniHtmlHopup.prototype.initContent = function () {
    this.elementKey.push("contentDiv");
    this.element["contentDiv"] = this.targetWindow.document.createElement("div");
    this.element["contentDiv"].innerHTML = this.config["content"];
    this.element["contentDiv"].setAttribute("class", "suryaniHtmlContent");
    this.element["contentDiv"].setAttribute("className", "suryaniHtmlContent");
}
//End SuryaniHtmlHopup
//Start SuryaniwHtmlWrapHopup
function SuryaniHtmlWrapHopup(param) {
    this.base = new SuryaniPopup(param);
    SuryaniUI.extend(this, this.base);
    this.initContent();
}
SuryaniHtmlWrapHopup.prototype.bindEvents = function () {
    var me = this;
    this.element["SuryaniReturnBtn"].style.display = "none";
    SuryaniUI.BindEvent(this.element["SuryaniCloseDiv"], "click", function () {
        me.hide();
        if (me.callBack.closeCallBack) {
            me.callBack.closeCallBack();
        }
    });
}
SuryaniHtmlWrapHopup.prototype.initContent = function () {
    this.elementKey.push("contentDiv");
    this.element["contentDiv"] = this.targetWindow.document.createElement("div");
    this.config["content"].appendTo(this.element["contentDiv"]).css("display", "block");
    this.element["contentDiv"].setAttribute("class", "suryaniHtmlContent");
    this.element["contentDiv"].setAttribute("className", "suryaniHtmlContent");
    $(".suryaniHtmlContent").find(".displayNone").removeClass("displayNone");
}
//End SuryaniwHtmlWrapHopup
//Start SuryaniHasCornerHtmlHopup
function SuryaniHasCornerHtmlHopup(param) {
    this.base = new SuryaniHtmlHopup(param);
    SuryaniUI.extend(this, this.base);
    this.initContent();
}
SuryaniHasCornerHtmlHopup.prototype.initContent = function () {
    this.elementKey.push("popupCornerLeft");
    this.element["popupCornerLeft"] = this.targetWindow.document.createElement("div");
    this.element["popupCornerLeft"].setAttribute("class", "suryaniCornerLeft");
    this.element["popupCornerLeft"].setAttribute("className", "suryaniCornerLeft");
    this.elementKey.push("popupCornerRight");
    this.element["popupCornerRight"] = this.targetWindow.document.createElement("div");
    this.element["popupCornerRight"].setAttribute("class", "suryaniCornerRight");
    this.element["popupCornerRight"].setAttribute("className", "suryaniCornerRight");
}
SuryaniHasCornerHtmlHopup.prototype.buildContent = function () {
    this.element["popupSpan"].setAttribute("class", "suryaniCornerHopup");
    this.element["popupSpan"].setAttribute("className", "suryaniCornerHopup");
    this.element["popupBorderTop"].appendChild(this.element["popupCornerLeft"]);
    this.element["popupBorderTop"].appendChild(this.element["popupCornerRight"]);
}
SuryaniHasCornerHtmlHopup.prototype.setSize = function () {
    this.element.popupDiv.style["width"] = (parseInt(this.size.width) + 50) + "px";
}
//End SuryaniHasCornerHtmlHopup
//Start ConfirmPopup
function SuryaniConfirmPopup(param) {
    this.base = new SuryaniPopup(param);
    SuryaniUI.extend(this, this.base);
    this.initContent();
}
SuryaniConfirmPopup.prototype.initContent = function () {
    this.elementKey.push("tipDiv");
    this.elementKey.push("ok");
    this.elementKey.push("cancel");
    this.elementKey.push("innerContentDiv");
    this.elementKey.push("innerButtonDiv");
    this.element["tipDiv"] = this.targetWindow.document.createElement("div");
    this.element["tipDiv"].innerHTML = this.config["content"];
    this.element["tipDiv"].setAttribute("class", "suryaniConfirmContent");
    this.element["tipDiv"].setAttribute("className", "suryaniConfirmContent");
    this.element["ok"] = this.targetWindow.document.createElement("input");
    this.element["ok"].setAttribute("type", "button");
    this.element["ok"].setAttribute("value", "yes");
    this.element["ok"].setAttribute("class", "okBtn");
    this.element["ok"].setAttribute("className", "okBtn");
    this.element["cancel"] = this.targetWindow.document.createElement("input");
    this.element["cancel"].setAttribute("value", "no");
    this.element["cancel"].setAttribute("type", "button");
    this.element["cancel"].setAttribute("class", "cancelBtn");//for firefox and safari
    this.element["cancel"].setAttribute("className", "cancelBtn");//for IE
    this.element["innerContentDiv"] = this.targetWindow.document.createElement("div");
    this.element["innerButtonDiv"] = this.targetWindow.document.createElement("div");
    this.element["innerButtonDiv"].setAttribute("class", "suryaniBtnsBox");
    this.element["innerButtonDiv"].setAttribute("className", "suryaniBtnsBox");
    this.callBack["ok"] = new SuryaniUIList();
    this.callBack["cancel"] = new SuryaniUIList();
}
SuryaniConfirmPopup.prototype.bindContentEvents = function () {
    var me = this;
    SuryaniUI.BindEvent(me.element["ok"], "click", function () {
        for (var i = 0; i < me.callBack["ok"].count(); i++) {
            me.callBack["ok"].item(i)();
        }
        me.close();
    });
    SuryaniUI.BindEvent(me.element["cancel"], "click", function () {
        for (var i = 0; i < me.callBack["cancel"].count(); i++) {
            me.callBack["cancel"].item(i)();
        }
        me.close();
    });
}
SuryaniConfirmPopup.prototype.buildContent = function () {
    this.element["innerContentDiv"].appendChild(this.element["tipDiv"]);
    this.element["innerButtonDiv"].appendChild(this.element["cancel"]);
    this.element["innerButtonDiv"].appendChild(this.element["ok"]);
    this.element["innerContentDiv"].appendChild(this.element["innerButtonDiv"]);
    this.element["contentDiv"].appendChild(this.element["innerContentDiv"]);
}
//End ConfirmPopup
//Start CountdownPopup
function CountdownPopup(param) {
    this.base = new SuryaniPopup(param);
    SuryaniUI.extend(this, this.base);
    this.config["autoClose"] = param["autoClose"] || 0;
    this.initContent();
}
CountdownPopup.prototype.initContent = function () {
    this.elementKey.push("tipDiv");
    this.element["tipDiv"] = this.targetWindow.document.createElement("div");
    this.element["tipDiv"].innerHTML = this.config["content"];
    this.element["tipDiv"].setAttribute("class", "countDownText lightRedText");
    this.element["tipDiv"].setAttribute("className", "countDownText lightRedText");
}
CountdownPopup.prototype.bindContentEvents = function () {
    var me = this;
    if (me.config["autoClose"]) {
        setTimeout(function () {
            try {
                me.close()
            } catch (ex) {
            }
        }, me.config["autoClose"]);
    }
}
CountdownPopup.prototype.buildContent = function () {
    this.element["contentDiv"].appendChild(this.element["tipDiv"]);
}
//End CountdownPopup

//Start Suryani Arrow Hopup
var SuryaniArrowHopupObj;
function SuryaniArrowHopupWindow(button, url, title, width, closeCallBack, showMask, isHtml, className) {
    if (SuryaniArrowHopupObj && SuryaniArrowHopupObj.action["hasShow"])
        SuryaniArrowHopupObj.close();

    var targetObj = $('body');
    var className = className || "";
    var leftPadding = 10;
    var rightPadding = 30;
    var hopupWidth = width + 23;
    var topSpace = $(button).offset().top - $(window).scrollTop() + $(button).height();
    var top = $(button).offset().top + $(button).height();
    var left = $(button).offset().left + $(button).width() / 2 - hopupWidth * 0.75;
    var rightGap = (left + hopupWidth) - targetObj.width();
    if (left < leftPadding) {
        left = leftPadding;
    }
    else if (rightGap > (-rightPadding)) {
        left -= (rightGap + rightPadding);
    }
    var arrowLeft = $(button).offset().left + $(button).width() / 2 - 18 - left;
    var param = {className: className, targetObj: targetObj, hasArrow: true, width: width, height: null, top: top, left: left, title: title, content: url, showMask: showMask, closeCallBack: closeCallBack };
    if (isHtml)
        SuryaniArrowHopupObj = new SuryaniHtmlHopup(param);
    else
        SuryaniArrowHopupObj = new SuryaniUrlHopup(param);

    SuryaniArrowHopupObj.element["popupArrow"].style.left = arrowLeft + "px";

    SuryaniArrowHopupObj.adjustPosition = function () {
        var className = SuryaniArrowHopupObj.config["className"].split(' ')[0];
        var hopupHeight = $(".suryaniArrowHopup").find(".suryaniPopup" + className).height();
        if (topSpace < hopupHeight) {
            this.element["popupSpan"].setAttribute("class", "suryaniArrowHopup");
            this.element["popupSpan"].setAttribute("className", "suryaniArrowHopup");
            $(".popupBorderBottom").remove(".popupArrow");
            this.element["popupBorderTop"].appendChild(this.element["popupArrow"]);
        }
        else {
            top = top - $(button).height() - hopupHeight + 5;
            this.element.popupDiv.style["top"] = top + "px";
            this.element["popupSpan"].setAttribute("class", "suryaniArrowHopup arrowDown");
            this.element["popupSpan"].setAttribute("className", "suryaniArrowHopup arrowDown");
            this.element["popupBorderBottom"].appendChild(this.element["popupArrow"]);
            $(".popupBorderTop").remove(".popupArrow");
        }
    }
    SuryaniArrowHopupObj.size.width = width + 23;
    SuryaniArrowHopupObj.show();
    if (isHtml)
        SuryaniArrowHopupObj.adjustPosition();
}
/* Suryani Common Hopup Prototypes --------END
 *********************************************/

/********************************************
 Suryani Dropdown List event
 *********************************************/
function initSuryaniDropdownList(dropClass, dropConClass, dropSelectClass, dropShadow) {
    //Drop down list
    $(dropClass).live('click', function () {
        $(this).find(dropConClass).find("ul").width($(this).find(dropSelectClass).outerWidth() + $(this).find(".dropDownArrowBtn").outerWidth() + dropShadow);
        if ($(this).find(dropConClass).css("display") == "none") {
            $(dropConClass).hide();
            $(this).find(dropConClass).show();
        }
        else {
            $(this).find(dropConClass).css("display", "none");
        }
    });
    $(dropClass).find("ul li").live('click', function () {
        var ListTitle = $(this).children("a").html();
        $(this).parent().find("li").removeClass("selected");
        $(this).addClass("selected");
        $(this).parents(dropClass).find(dropSelectClass).html(ListTitle);
    });
    $(dropClass).hover(
        function () {
        },
        function () {
            $(dropConClass, this).css("display", "none");
        }
    );
}
/*  Suryani Dropdown List event -----------END
 *********************************************/

/********************************************
 Suryani Limited Textarea event
 *********************************************/
function textCounter(field, countfield, maxlimit) {
    if ($(field).val().length > maxlimit) {
        var subs = $(field).val().substring(0, maxlimit);
        $(field).val(subs);
    }
    else {
        var remLen = maxlimit - $(field).val().length;
        $(countfield).val(remLen);
    }
}
//Calculate the rest of text on Limited Textarea
function calculateCounts(field, countfield, maxlimit) {
    if ($(countfield).val() == maxlimit) {
        var Notecount = $(countfield).val() - $(field).val().length;
        Notecount = (Notecount < 0) ? 0 : Notecount;
        $(countfield).val(Notecount);
    }
}
/*  Suryani Limited Text Area event -------END
 *********************************************/

/********************************************
 Suryani commonHopup sisters sites Objects
 *********************************************/
var suryaniUrlNoMarginPopup;
function suryaniNoMarginPopupWindow(width, url, showMask, closeCallback, top, title) {
    var title = title || "";
    var urlPopupPara = { width: width, height: null, top: top, left: null, title: title, content: url, showMask: showMask, language: 'en-us', closeCallBack: closeCallback };
    if (top == undefined) {
        top = null;
    }
    suryaniUrlNoMarginPopup = new SuryaniUrlHopup(urlPopupPara);
    suryaniUrlNoMarginPopup.size.width = width + 5;
    suryaniUrlNoMarginPopup.show();
}
function resetSuryaniUrlNoMarginWidth(width) {
    suryaniUrlNoMarginPopup.size.width = width + 23;
    suryaniUrlNoMarginPopup.element["url"].setAttribute("width", width + "px");
    suryaniUrlNoMarginPopup.setSize();
}
function resetSuryaniUrlNoMarginHeight(height) {
    suryaniUrlNoMarginPopup.element["url"].setAttribute("height", height + "px");
    suryaniUrlNoMarginPopup.size.height = height;
    suryaniUrlNoMarginPopup.setPosition();
}
function resetSuryaniUrlNoMarginAnimationHeight(currentHeight, newHeight) {
    var t = 0, intervalsHeight = newHeight - currentHeight;

    function changeHeight() {
        suryaniUrlNoMarginPopup.element["url"].setAttribute("height", t * intervalsHeight / 30 + currentHeight + "px");
        suryaniUrlNoMarginPopup.size.height = t * intervalsHeight / 30 + currentHeight;
        t++;
        if (t <= 30)
            setTimeout(changeHeight, 30);
    }

    changeHeight()
}

var suryaniHtmlHopupObj;
function suryaniHtmlHopupWindow(width, height, title, content, showMask, closeCallBack, top) {
    var top = top || null;
    var htmlPopupPara = { width: width, height: height, top: top, left: null, title: title, content: content, showMask: showMask, language: 'en-us', closeCallBack: closeCallBack };
    suryaniHtmlHopupObj = new SuryaniHtmlHopup(htmlPopupPara);
    suryaniHtmlHopupObj.size.width = width + 23;
    suryaniHtmlHopupObj.show();
}

var readFAQsHtmlHopupObj, readFAQsClass = "FAQs"
function readFAQsHtmlHopupWindow(width, height, title, content, showMask, closeCallBack, top) {
    var top = top || null;
    var htmlPopupPara = { width: width, height: height, top: top, left: null, title: title, content: content, showMask: showMask, language: 'en-us', closeCallBack: closeCallBack, className: readFAQsClass };
    readFAQsHtmlHopupObj = new SuryaniHtmlHopup(htmlPopupPara);
    readFAQsHtmlHopupObj.size.width = width + 23;
    readFAQsHtmlHopupObj.show();
}

function suryaniImageHopupWindow(imageUrl, width) {
    var width = width || 300;
    var imageHtml = "<img class='imageHopupContent displayNone' src='" + imageUrl + "' />";
    var loadingHtml = "<div class='loadingDiv' style='padding:50px 0;'><span>Please Wait ...</span></div>";
    var htmlPopupPara = {className: " suryaniHtmlNoMargin suryaniImageHopup", width: width, height: null, top: null, left: null, title: "", content: loadingHtml + imageHtml, showMask: true, language: 'en-us', closeCallBack: null };
    suryaniImageHopupObj = new SuryaniHtmlHopup(htmlPopupPara);
    suryaniImageHopupObj.size.width = width + 23;
    suryaniImageHopupObj.show();
    $(".suryaniImageHopup").find("img.imageHopupContent").load(function () {
        $(".suryaniImageHopup").find(".loadingDiv").hide();
        $(this).show();
        var newWidth = this.width + 23;
        var newHeight = this.height;
        suryaniImageHopupObj.size.width = newWidth;
        suryaniImageHopupObj.element["popupDiv"].setAttribute("width", newWidth + "px");
        suryaniImageHopupObj.size.height = newHeight;
        suryaniImageHopupObj.element["popupDiv"].setAttribute("height", newHeight + "px");
        suryaniImageHopupObj.setSize();
        suryaniImageHopupObj.setPosition();
    });
}

var suryaniHtmlWrapHopupObj;
function suryaniHtmlWrapHopupWindow(width, height, title, content, showMask, closeCallBack, top) {
    var top = top || null;
    var htmlWrapPopupPara = { width: width, height: height, top: top, left: null, title: title, content: content, showMask: showMask, language: 'en-us', closeCallBack: closeCallBack };
    suryaniHtmlWrapHopupObj = new SuryaniHtmlWrapHopup(htmlWrapPopupPara);
    suryaniHtmlWrapHopupObj.size.width = width + 23;
    suryaniHtmlWrapHopupObj.show();
}

var SuryaniNoCloseBtnHopupObj;
function SuryaniNoCloseBtnHopupHopup(width, height, content, showMask, closeCallback) {
    var htmlWrapPopupPara = { className: ' NoCloseBtn', width: width, height: height, top: null, left: null, title: '', content: content, showMask: showMask, closeCallBack: closeCallback };
    SuryaniNoCloseBtnHopupObj = new SuryaniHtmlWrapHopup(htmlWrapPopupPara);
    SuryaniNoCloseBtnHopupObj.size.width = width + 10;
    SuryaniNoCloseBtnHopupObj.show();
}

var SuryaniConfirmPopupObj;
function suryaniConfirmPopup(width, height, top, content, title, showMask, callbackFunction) {
    var confirmPopupPara = {width: width, height: height, top: top, title: title, content: content, showMask: showMask };
    SuryaniConfirmPopupObj = new SuryaniConfirmPopup(confirmPopupPara);
    SuryaniConfirmPopupObj.addCallBack("ok", callbackFunction);
    SuryaniConfirmPopupObj.show();
}

function CountdownPopupWindow(width, height, title, content, showMask) {
    var tipPopupPara = { autoClose: 5000, width: width, height: height, top: null, left: null, title: title, content: content, showMask: showMask, language: 'en-us', closeCallBack: null };
    var tipPopup = new CountdownPopup(tipPopupPara);
    tipPopup.show();
}


